#define _CRT_SECURE_NO_WARNINGS 1
#include <unordered_set>
using namespace std;
struct ListNode {
    int val;
    struct ListNode *next;
    ListNode(int x) :
        val(x), next(NULL) {
    }
};

class Solution {
public:
    ListNode* EntryNodeOfLoop(ListNode* pHead)
    {
        unordered_set<ListNode*> se;
        ListNode* cur = pHead;
        while (cur)
        {
            if (se.find(cur) != se.end())
            {
                return cur;
            }
            se.insert(cur);
            cur = cur->next;
        }
        return nullptr;
    }
};